<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2020/12/14
  Time: 18:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>更新信息</title>
    <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>图书信息更新</legend>
</fieldset>

<form class="layui-form" action="" lay-filter="myForm" id="myForm">
    <input type="hidden" value="${param.get("bookId")}" id="bookId">
    <div class="layui-form-item">
        <label class="layui-form-label">图书类别</label>
        <div class="layui-input-block">
            <select name="interest" lay-filter="showCategory" id="showCategory">

            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">书名</label>
        <div class="layui-input-block">
            <input type="text" name="bookName"   placeholder="请输入书名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图书价格</label>
        <div class="layui-input-block">
            <input type="text" name="bookPrice" placeholder="请输入图书价格" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">上架日期</label>
                <div class="layui-input-block">
                    <input type="text" name="groundingdate" id="date" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">是否在售</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="y" title="是">
            <input type="radio" name="sex" value="n" title="否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库存</label>
        <div class="layui-input-block">
            <input type="text" name="inventory  " placeholder="请输入库存" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-block">
            <input type="text" name="author" placeholder="请输入作者" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">出版社</label>
        <div class="layui-input-block">
            <input type="text" name="press" placeholder="请输入出版社" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">修改次数</label>
        <div class="layui-input-block">
            <input type="text" name="editNum" placeholder="请输入修改次数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">印刷日期</label>
                <div class="layui-input-block">
                    <input type="text" name="printDate" id="date1" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">版次</label>
        <div class="layui-input-block">
            <input type="text" name="printCount" placeholder="请输入版次" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">国标书号</label>
        <div class="layui-input-block">
            <input type="text" name="isbn" placeholder="请输入国标书号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字数</label>
        <div class="layui-input-block">
            <input type="text" name="wordCount" placeholder="请输入字数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">页数</label>
        <div class="layui-input-block">
            <input type="text" name="pageCount" placeholder="请输入页数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开数</label>
        <div class="layui-input-block">
            <input type="text" name="style" placeholder="请输入开数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">纸质</label>
        <div class="layui-input-block">
            <input type="text" name="page" placeholder="请输入纸质" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">包装</label>
        <div class="layui-input-block">
            <input type="text" name="pack" placeholder="请输入包装" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">已售数量</label>
        <div class="layui-input-block">
            <input type="text" name="salenum" placeholder="请输入已售数量" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">顾客评分</label>
        <div class="layui-input-block">
            <input type="text" name="customeScore" placeholder="请输入顾客评分" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">推荐信息</label>
        <div class="layui-input-block">
            <input type="text" name="recommend" placeholder="请输入推荐信息" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图书简介</label>
        <div class="layui-input-block">
            <input type="text" name="messages" placeholder="请输入图书简介" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">作者简介</label>
        <div class="layui-input-block">
            <input type="text" name="authorMsg" placeholder="请输入作者简介" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">目录</label>
        <div class="layui-input-block">
            <input type="text" name="list" placeholder="请输入目录" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">媒体评论</label>
        <div class="layui-input-block">
            <input type="text" name="mediaComment" placeholder="请输入媒体评论" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片路径</label>
        <div class="layui-input-block">
            <input type="text" name="imagepath" placeholder="请输入图片路径" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属系列</label>
        <div class="layui-input-block">
            <input type="text" name="seriesName" placeholder="请输入所属系列" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">当当网价格</label>
        <div class="layui-input-block">
            <input type="text" name="dangprice" placeholder="请输入当当网价格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片名称</label>
        <div class="layui-input-block">
            <input type="text" name="productImage" placeholder="请输入图片名称" autocomplete="off" class="layui-input">
            <img src="#" id="image">
        </div>
    </div>
    <div class="layui-form-item" >
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>

<script type="text/javascript" src="layui/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript">

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate;
        let bookId = $("#bookId").val();
        $.ajax({
            url:"products/"+bookId,
            type:"get",
            dataType:"json",
            success:function (data){
                console.log(data)
                var bookCid=data.cid;
                var imagepath=data.imagepath;
                //表单赋值
                form.val("myForm",{
                    "bookName":data.bookName,
                    "bookPrice":data.bookPrice,
                    "groundingdate":data.groundingdate,
                    "bookState":data.bookState,
                    "inventory":data.inventory,
                    "author":data.author,
                    "press":data.press,
                    "editNum":data.editnum,
                    "printDate":data.printDate,
                    "printCount":data.printCount,
                    "isbn":data.isbn,
                    "wordCount":data.wordCount,
                    "pageCount":data.pageCount,
                    "style":data.style,
                    "page":data.page,
                    "pack":data.pack,
                    "salenum":data.salenum,
                    "customeScore":data.customeScore,
                    "recommend":data.recommend,
                    "messages":data.messages,
                    "authorMsg":data.authorMsg,
                    "list":data.list,
                    "mediaComment":data.mediaComment,
                    "imagepath":data.imagepath,
                    "seriesName":data.seriesName,
                    "dangprice":data.dangprice,
                    "productImage":data.productImage
                });
                $("[name='groundingdate']").val(data.groundingdate)
                $("[name='printDate']").val(data.printDate)
                form.render();

                //查询2级类别
                var cid=2;
                $.ajax({
                    url: "categorys/"+cid,
                    type: "get",
                    dataType: "json",
                    success:function (data){
                        var htm='';
                        for (var i=0;i<data.length;i++){
                            if (bookCid==data[i].categoryId){
                                htm+="<option selected=\"selected\" value=\""+data[i].categoryId+"\">"+data[i].categoryName+"</option>";
                            }else {
                                htm+="<option value=\""+data[i].categoryId+"\">"+data[i].categoryName+"</option>";
                            }
                        }
                        $("#showCategory").append(htm)
                        //动态更新表单后重新渲染表单中的select
                        form.render("select");
                    }
                });

                //查询图片(给img标签地址赋值)
                $("#image").attr("src","image/"+imagepath);

            }
        });

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });


        //监听提交
        form.on('submit(myForm)', function(data){
            var product=data.field;
            console.log(product)
            return false;
        });

    });
</script>
</body>
</html>
